<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="docgen-resources/docgen.css" type="text/css">
  <meta name="generator" content="FreeMarker Docgen (DocBook 5)">
  <title>
    FreeMarker Manual - Jython wrapper
  </title>
    <script type="text/javascript" src="docgen-resources/jquery.js"></script>
    <script type="text/javascript" src="docgen-resources/linktargetmarker.js"></script>
</head>
<body>

    <div class="navigation">
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_misc.html">Miscellaneous</a>
            <b>></b>
          Jython wrapper
</span>    </div>
    <div class="bookmarks">
<span class="bookmarks">Bookmarks:
<a href="alphaidx.html">Alpha. index</a>, <a href="gloss.html">Glossary</a>, <a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a>, <a href="ref_builtins_alphaidx.html">?builtins</a>, <a href="ref_directive_alphaidx.html">#directives</a>, <a href="ref_specvar.html">.spec_vars</a>, <a href="app_faq.html">FAQ</a>, <a href="api/index.html">API</a>, <a href="../index.html">Home</a></span>    </div>
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="xgui.html"><span class="hideA">Next page: </span>XML Processing Guide</a></div><div class="pagerButton"><a href="pgui_misc_ant.html">Previous page</a></div><div class="pagerButton"><a href="pgui_misc.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    </div>

<div id="mainContent">

  
  
  
  
  <h1 class="rank_section1"
        id="pageTopTitle">
<a name="pgui_misc_jythonwrapper"></a>Jython wrapper  </h1>
    
    <div class="toc">
      <p>
        <b>
            Page Contents
        </b>
      </p>
      
  <ul class="noMargin">
      <li style="padding-bottom: 0.5em"><i><a href="#docgen_afterTheTOC">Intro.</a></i></li>
      <li>
        <a href="#autoid_64">TemplateHashModel functionality</a>
      </li>
      <li>
        <a href="#autoid_65">TemplateScalarModel functionality</a>
      </li>
      <li>
        <a href="#autoid_66">TemplateBooleanModel functionality</a>
      </li>
      <li>
        <a href="#autoid_67">TemplateNumberModel functionality</a>
      </li>
      <li>
        <a href="#autoid_68">TemplateSequenceModel functionality</a>
      </li>
  </ul>
    </div>
    <a name="docgen_afterTheTOC"></a>
    
<p>The <tt style="color: #A03D10">freemarker.ext.jython</tt> package consists of
        models that enable any Jython object to be used as a
        <tt style="color: #A03D10">TemplateModel</tt>. In the very basic case, you only
        need to call the</p><div align="left" class="programlisting"><table bgcolor="#F8F8F8" cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td><table bgcolor="#F8F8F8" cellspacing="0" cellpadding="4" border="0" width="100%" style="margin: 0px"><tr><td><pre style="margin: 0px">
public TemplateModel wrap(Object obj);&nbsp;<span style="font-size: 1pt"> </span></pre></td></tr></table></td><td width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td></tr><tr valign="top"><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td><td height="1" width="1" bgcolor="black"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></td>      </tr>
</table>  </div>
<p>method of the
        <tt style="color: #A03D10">freemarker.ext.jython.JythonWrapper</tt> class. This
        method will wrap the passed object into an appropriate
        <tt style="color: #A03D10">TemplateModel</tt>. Below is a summary of the properties
        of returned model wrappers. Let's assume that the model that resulted
        from the <tt style="color: #A03D10">JythonWrapper</tt> call on object
        <tt style="color: #A03D10">obj</tt> is named <tt style="color: #A03D10">model</tt> in the
        template model root for the sake of the following discussion.</p>
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_64"></a>TemplateHashModel functionality  </h2>


          <p><tt style="color: #A03D10">PyDictionary</tt> and
          <tt style="color: #A03D10">PyStringMap</tt> will be wrapped into a hash model.
          Key lookups are mapped to the <tt style="color: #A03D10">__finditem__</tt>
          method; if an item is not found, a model for <tt style="color: #A03D10">None</tt>
          is returned.</p>
        
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_65"></a>TemplateScalarModel functionality  </h2>


          <p>Every python object will implement
          <tt style="color: #A03D10">TemplateScalarModel</tt> whose
          <tt style="color: #A03D10">getAsString()</tt> method simply delegates to
          <tt style="color: #A03D10">toString()</tt>.</p>
        
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_66"></a>TemplateBooleanModel functionality  </h2>


          <p>Every python object will implement
          <tt style="color: #A03D10">TemplateBooleanModel</tt> whose
          <tt style="color: #A03D10">getAsBoolean()</tt> method simply delegates to
          <tt style="color: #A03D10">__nonzero__()</tt> in accordance with Python semantics
          of true/false.</p>
        
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_67"></a>TemplateNumberModel functionality  </h2>


          <p>Model wrappers for <tt style="color: #A03D10">PyInteger</tt>,
          <tt style="color: #A03D10">PyLong</tt>, and <tt style="color: #A03D10">PyFloat</tt> objects
          implement <tt style="color: #A03D10">TemplateNumberModel</tt> whose
          <tt style="color: #A03D10">getAsNumber()</tt> method returns
          <tt style="color: #A03D10">__tojava__(java.lang.Number.class)</tt>.</p>
        
            
  
  
  
  <h2 class="rank_section2"
        >
<a name="autoid_68"></a>TemplateSequenceModel functionality  </h2>


          <p>Model wrappers for all classes that extend
          <tt style="color: #A03D10">PySequence</tt> will implement
          <tt style="color: #A03D10">TemplateSequenceModel</tt> and thus their elements
          will be accessible by index using the <tt style="color: #A03D10">model[i]</tt>
          syntax, which will delegate to <tt style="color: #A03D10">__finditem__(i)</tt>.
          You can also query the length of the array or the size of the list
          using the <tt style="color: #A03D10">model?size</tt> built-in, which will
          delegate to <tt style="color: #A03D10">__len__()</tt>.</p>
          
</div>

    <div class="navigation">
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="xgui.html"><span class="hideA">Next page: </span>XML Processing Guide</a></div><div class="pagerButton"><a href="pgui_misc_ant.html">Previous page</a></div><div class="pagerButton"><a href="pgui_misc.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_misc.html">Miscellaneous</a>
            <b>></b>
          Jython wrapper
</span>    </div>
    </div>

<table border=0 cellspacing=0 cellpadding=0 width="100%">
    <tr>
      <td colspan=2><img src="docgen-resources/img/none.gif" width=1 height=8 alt=""></td>
    <tr>
      <td align="left" valign="top"><span class="smallFooter">
            FreeMarker Manual -- For FreeMarker 2.3.20
            <br>
          HTML generated: 2013-06-27 20:54:33 GMT
      </span></td>
      <td align="right" valign="top"><span class="smallFooter">
          <a href="http://www.xmlmind.com/xmleditor/">
            <img src="docgen-resources/img/xxe.gif" alt="Edited with XMLMind XML Editor">
          </a>
      </span></td>
    </tr>
</table>
  <!-- Put pre-loaded images here: -->
  <div style="display: none">
    <img src="docgen-resources/img/linktargetmarker.gif" alt="Here!" />
  </div>
</body>
</html>

